home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / BSDVBLLib 1.0 / BSD VBL Example / main.cp < prev   
Encoding:
Text File  |  1997-08-03  |  2.6 KB  |  111 lines  |  [TEXT/CWIE]

  1. /*
  2.     BSD VBL Example v1.0
  3.     Created by Scott Dunbar
  4.     8/3/97
  5. */
  6.  
  7.     // GWorld & Copybits routines (not included)
  8. #include <BSDOffscreenLib.h>
  9.  
  10.     // VBL routines
  11. #include <BSDVBLLib.h>
  12.  
  13.     // Menubar routines (not included)
  14. #include <BSDMenubarLib.h>
  15.  
  16. WindowPtr        window;        // the main window
  17. GWorldPtr        offscreen;    // the GWorld that will hold the picture
  18. PicHandle        pic;        // a picture of the BuggySoft Development logo :)
  19. Rect            bounds,        // the GWorld bounds
  20.                 dest;        // the destination rect to draw to
  21. short            horz = 1,    // move right
  22.                 vert = 1;    //     and down initially
  23.  
  24. void main (void) {
  25.         // initialize MacOS routines and max our app zone
  26.     InitGraf(&qd.thePort);
  27.     InitFonts();
  28.     InitWindows();
  29.     InitMenus();
  30.     InitDialogs(nil);
  31.     InitCursor();
  32.     TEInit();
  33.     MaxApplZone();
  34.     
  35.         // load our picture and lock it down
  36.     pic = GetPicture(128);
  37.     HLock((Handle)pic);
  38.     
  39.         // setup a few rects
  40.     Rect r = bounds = (*pic)->picFrame;
  41.     bounds.right += 2;
  42.     bounds.bottom += 2;
  43.     dest = bounds;
  44.     OffsetRect(&r, 1, 1);
  45.     
  46.         // create the GWorld
  47.     offscreen = CreateGWorld(0, bounds, nil, nil, 0, nil, none);
  48.     
  49.         // open the GWorld and draw the logo into it
  50.     OpenGWorld(offscreen);
  51.     PaintRect(&offscreen->portRect);
  52.     DrawPicture(pic, &r);
  53.     CloseGWorld();
  54.     
  55.         // unlock and release the pict resource
  56.     HUnlock((Handle)pic);
  57.     ReleaseResource((Handle)pic);
  58.     
  59.         // hide the cursor and menubar
  60.     HideCursor();
  61.     HideMenuBar();
  62.  
  63.         // make a full-screen window and paint it black
  64.     window = NewCWindow(nil, &qd.screenBits.bounds, "\p", true, plainDBox, (WindowPtr)-1L, false, 0);
  65.     SetPort(window);
  66.     PaintRect(&window->portRect);
  67.     
  68.         // initialize the VBL library
  69.     InitVBLLib();
  70.     
  71.         // loop until the mouse button is pressed
  72.     while (!Button()) {
  73.         
  74.             // check vblUpdate
  75.         if (vblUpdate) {
  76.         
  77.                 // move the logo's dest rect a little bit
  78.             OffsetRect(&dest, horz, vert);
  79.             
  80.                 // check to see if we hit the edge of the screen and bounce back the other way
  81.             if (dest.left <= -1) horz = -horz;
  82.             if (dest.top <= -1) vert = -vert;
  83.             if (dest.right >= (window->portRect.right + 1)) horz = -horz;
  84.             if (dest.bottom >= (window->portRect.bottom + 1)) vert = -vert;
  85.  
  86.                 // draw to the screen
  87.             GWorld2WindowRect(offscreen, window, offscreen->portRect, dest, srcCopy);
  88.         }
  89.     }
  90.     
  91.         // wait for the user to release the mouse button (cleaner feeling :)
  92.     while (Button());
  93.         
  94.         // dispose of the VBL library
  95.     DisposeVBLLib();
  96.     
  97.         // show the cursor and menubar
  98.     ShowMenuBar();
  99.     ShowCursor();
  100.     
  101.         // dispose our GWorld and window
  102.     DisposeGWorld(offscreen);
  103.     DisposeWindow(window);
  104.     
  105.         // flush out those nasty little mouse clicks
  106.     FlushEvents(mDownMask + mUpMask, 0);
  107.     
  108.         // quit
  109.     ExitToShell();
  110. }
  111.